<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" contentType="text/html; charset=utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<jsp:include page="../head.jsp"></jsp:include>
<html>
<%
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/";
%>
<head>
<script type="text/javascript">
function addAccessories(){
	t1.insertRow().insertCell().innerHTML = '<tr><td><input type="checkbox" name="tt" /> <input type="file" name="accessories" size="70" /></td></tr>';
}
function delAccessories(){
	var c = document.getElementsByName('tt');
	for(var i=c.length-1; i>=0; i--)
	if(c[i].checked)
	t1.deleteRow(i);
}

function deleAccess(accessId,contractCode,contractId){
	$.post('./TbContractServlet','method=deleAccessById&accessId='+accessId+'&contractCode='+contractCode+'&num='+parseInt(Math.random()*(10000000))+'&contractId='+contractId,backFun);
}
function backFun(date){
	$('#showAccess').html(date);
}
</script>
</head>
<body>
<form action="TbContractServlet?method=${sessionScope.tbContract==null?'add':'edit'}&contractType=${sessionScope.contractType }&isArchive=0"  enctype="multipart/form-data" method="post" >
<table>
<tr><td colspan="2" align='center' >${sessionScope.tbContract.contractCode==null?'新增':'修改'}${sessionScope.contractType==0?'供应':'合作' }商合同</td></tr>
<tr>
    <td>合同编号</td>
    <td><input type='text' name='contractCode' id='contractCode' value='${sessionScope.tbContract.contractCode }' ${sessionScope.tbContract.contractCode==null?'':' readonly '} /></td>
</tr>
<tr>
    <td>合同名称</td>
    <td><input type='text' name='contractName' id='contractName' value='${sessionScope.tbContract.contractName }' /></td>
</tr>
<tr>
    <td>合同有效期 </td>
    <td>从<input type='text' size='10' name='startDateSigned' id='startDateSigned'  class="Wdate" size="20" readonly onclick="WdatePicker({el:this,dateFmt:'yyyy-MM-dd'})" value='${sessionScope.tbContract.startDateSigned }' />
          至<input type='text' size='10' name='endDateSigned' id='endDateSigned' class="Wdate" size="20" readonly onclick="WdatePicker({el:this,dateFmt:'yyyy-MM-dd'})" value='${sessionScope.tbContract.endDateSigned }' /></td>
</tr>
<tr>
    <td>合同状态</td>
    <td>
    <select name='contractState' id='contractState'>
    <option value='0' ${sessionScope.tbContract.contractState==0?' selected ':'' }>施工中</option>
    <option value='1' ${sessionScope.tbContract.contractState==1?' selected ':'' }>验收中</option>
    <option value='2' ${sessionScope.tbContract.contractState==2?' selected ':'' }>回款中</option>
    <option value='3' ${sessionScope.tbContract.contractState==3?' selected ':'' }>已完工</option>
    <option value='4' ${sessionScope.tbContract.contractState==4?' selected ':'' }>整改中</option>
    </select>
    </td>
</tr>
<tr>
    <td>合同价格</td>
    <td><input type='text' name='contractPrice' id='contractPrice' value='${sessionScope.tbContract.contractPrice }' /></td>
</tr>
    <c:if test="${sessionScope.tbContract!=null}">
    	<tr>
    	<td>已存在附件</td>
    	<td>
    	<div id="showAccess" name="showAccess">
    	  		 <c:forEach items="${sessionScope.tbAccessorList}" var="tbAccessorList" varStatus="status">
		    	 	<a href="../../../upload/${tbAccessorList.accessoriesFileName  }" id="${tbAccessorList.accessoriesId }">${tbAccessorList.accessoriesFileName }</a>
		    	 	<input type="button"  value="删除" onclick="deleAccess('${tbAccessorList.accessoriesId}','${sessionScope.tbContract.contractCode}','${sessionScope.tbContract.contractId }')"/>
	    	 	</c:forEach>
    	  </div>
    	</td>
    	</tr>
    
    </c:if>
<tr>
    <td>附件</td>
    <td>
    <button type="button" onclick='addAccessories();'>添加附件</button> <button type="button" onclick='delAccessories();'>删除附件</button>
    <TABLE id=t1 border=1>
    <tr><td>&nbsp; &nbsp;</td></tr>
    <tr><td><input type="checkbox" name="tt" checked /><input type="file" name="accessories" size="70" /></td></tr>
    </TABLE>
    </td>
</tr>
<tr>
    <td>${sessionScope.contractType==0?'供应':'合作' }商名称</td>
    <td>
    <select name='companyId' id='companyId' >
     <c:forEach items="${sessionScope.tbCompanyALL}" var="tbCompanyList" varStatus="status">
	    <option value='${tbCompanyList.companyId }' ${tbCompanyList.companyId==sessionScope.tbContract.companyId ?' selected ':''} >${tbCompanyList.companyName }</option> 
     </c:forEach>
     </select>
    </td>
</tr>
<tr>
    <td>${sessionScope.contractType==0?'供应':'合作' }商联系人</td>
    <td>
    <input type='text' name='companyContract' id='companyContract' value='${sessionScope.tbContract.companyContract }' />
    </td>
</tr>
<tr>
	<td>合同签订时间</td>
	<td><input type="text" name="contractSignedTime" id="contractSignedTime" class="Wdate" size="20" readonly onclick="WdatePicker({el:this,dateFmt:'yyyy-MM-dd'})"  value="${sessionScope.tbContract.contractSignedTime }"/></td>
</tr>
<tr>
	<td>我方签订人</td>
	<td><input type="text" name="ourCompanyUser" id="ourCompanyUser" value="${sessionScope.tbContract.ourCompanyUser }"/></td>
</tr>
<tr>
    <td>施工内容</td>
    <td><textarea  name='contractContent' id='contractContent' cols="70" rows="5" >${sessionScope.tbContract.contractContent }</textarea></td>
</tr>
<tr>
    <td colspan='2' align="center"><input type="submit" name="btsubmit" id="btsubmit" value="${sessionScope.tbContract==null?'添加':'修改'}" /><input type='reset' value='重置' /><input type='button' value='返回' onclick='history.go(-1);' /></td>
</tr></table>
</form>
<jsp:include page="../foot.jsp"></jsp:include>
<script type="text/javascript">
<!--
t1.deleteRow(0);
//-->
</script>
</body>
</html>